home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gas_251.zip / bin_251 / bfd / elf32-ppc.c < prev    next >
C/C++ Source or Header  |  1994-06-21  |  42KB  |  865 lines

  1. /* PowerPC-specific support for 32-bit ELF
  2.    Copyright 1994 Free Software Foundation, Inc.
  3.    Written by Ian Lance Taylor, Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* This file is based on a preliminary PowerPC ELF ABI.  The
  22.    information may not match the final PowerPC ELF ABI.  It includes
  23.    suggestions from the in-progress Embedded PowerPC ABI, and that
  24.    information may also not match.  */
  25.  
  26. #include "bfd.h"
  27. #include "sysdep.h"
  28. #include "libbfd.h"
  29. #include "libelf.h"
  30.  
  31. static bfd_reloc_status_type ppc_elf_unsupported_reloc
  32.   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
  33. static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
  34.   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
  35. static bfd_reloc_status_type ppc_elf_got16_reloc
  36.   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
  37. static const struct reloc_howto_struct *bfd_elf32_bfd_reloc_type_lookup
  38.   PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
  39. static void powerpc_info_to_howto
  40.   PARAMS ((bfd *abfd, arelent *cache_ptr, Elf32_Internal_Rela *dst));
  41.  
  42. #define USE_RELA
  43.  
  44. enum reloc_type
  45. {
  46.   R_PPC_NONE = 0,
  47.   R_PPC_ADDR32,
  48.   R_PPC_ADDR24,
  49.   R_PPC_ADDR16,
  50.   R_PPC_ADDR16_LO,
  51.   R_PPC_ADDR16_HI,
  52.   R_PPC_ADDR16_HA,
  53.   R_PPC_ADDR14,
  54.   R_PPC_ADDR14_BRTAKEN,
  55.   R_PPC_ADDR14_BRNTAKEN,
  56.   R_PPC_REL24,
  57.   R_PPC_REL14,
  58.   R_PPC_REL14_BRTAKEN,
  59.   R_PPC_REL14_BRNTAKEN,
  60.   R_PPC_GOT16,
  61.   R_PPC_GOT16_LO,
  62.   R_PPC_GOT16_HI,
  63.   R_PPC_GOT16_HA,
  64.   R_PPC_PLT24,
  65.   R_PPC_COPY,
  66.   R_PPC_GLOB_DAT,
  67.   R_PPC_JMP_SLOT,
  68.   R_PPC_RELATIVE,
  69.   R_PPC_LOCAL24PC,
  70.   R_PPC_UADDR32,
  71.   R_PPC_UADDR16,
  72.  
  73.   /* The remaining relocs are from the Embedded ELF ABI, and are not
  74.      in the SVR4 ELF ABI.  */
  75.   R_PPC_CGOT16,
  76.   R_PPC_CGOT16_LO,
  77.   R_PPC_CGOT16_HI,
  78.   R_PPC_CGOT16_HA,
  79.   R_PPC_GOT_REG,
  80.   R_PPC_CGOT_REG,
  81.   R_PPC_NADDR16,
  82.   R_PPC_NADDR32,
  83.   R_PPC_NADDR24,
  84.   R_PPC_DISP16,
  85.   R_PPC_GOTRL16,
  86.   R_PPC_GOTRLA16,
  87.   R_PPC_CGOTRL16,
  88.   R_PPC_CGOTRLA16,
  89.   R_PPC_max
  90. };
  91.  
  92. static reloc_howto_type elf_powerpc_howto_table[] =
  93. {
  94.   /* This reloc does nothing.  */
  95.   HOWTO (R_PPC_NONE,            /* type */                                 
  96.      0,                    /* rightshift */                           
  97.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  98.      32,                    /* bitsize */                   
  99.      false,                    /* pc_relative */                          
  100.      0,                    /* bitpos */                               
  101.      complain_overflow_bitfield, /* complain_on_overflow */
  102.      bfd_elf_generic_reloc, /* special_function */                     
  103.      "R_PPC_NONE",          /* name */                                 
  104.      false,                    /* partial_inplace */                      
  105.      0,                /* src_mask */                             
  106.      0,                    /* dst_mask */                             
  107.      false),                /* pcrel_offset */
  108.  
  109.   /* A standard 32 bit relocation.  */
  110.   HOWTO (R_PPC_ADDR32,          /* type */                                 
  111.      0,                    /* rightshift */                           
  112.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  113.      32,                    /* bitsize */                   
  114.      false,                    /* pc_relative */                          
  115.      0,                    /* bitpos */                               
  116.      complain_overflow_bitfield, /* complain_on_overflow */
  117.      bfd_elf_generic_reloc, /* special_function */                     
  118.      "R_PPC_ADDR32",    /* name */
  119.      false,                    /* partial_inplace */                      
  120.      0,                /* src_mask */                             
  121.      0xffffffff,           /* dst_mask */                             
  122.      false),                /* pcrel_offset */
  123.  
  124.   /* An absolute 26 bit branch; the lower two bits must be zero.
  125.      FIXME: we don't check that, we just clear them.  */
  126.   HOWTO (R_PPC_ADDR24,          /* type */                                 
  127.      0,                    /* rightshift */                           
  128.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  129.      26,                    /* bitsize */                   
  130.      false,                    /* pc_relative */                          
  131.      0,                    /* bitpos */                               
  132.      complain_overflow_bitfield, /* complain_on_overflow */
  133.      bfd_elf_generic_reloc, /* special_function */                     
  134.      "R_PPC_ADDR24",    /* name */
  135.      false,                    /* partial_inplace */                      
  136.      0,                /* src_mask */                             
  137.      0x3fffffc,            /* dst_mask */                             
  138.      false),                /* pcrel_offset */
  139.  
  140.   /* A standard 16 bit relocation.  */
  141.   HOWTO (R_PPC_ADDR16,          /* type */                                 
  142.      0,                    /* rightshift */                           
  143.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  144.      16,                    /* bitsize */                   
  145.      false,                    /* pc_relative */                          
  146.      0,                    /* bitpos */                               
  147.      complain_overflow_bitfield, /* complain_on_overflow */
  148.      bfd_elf_generic_reloc, /* special_function */                     
  149.      "R_PPC_ADDR16",    /* name */
  150.      false,                    /* partial_inplace */                      
  151.      0,                /* src_mask */                             
  152.      0xffff,            /* dst_mask */                             
  153.      false),                /* pcrel_offset */
  154.  
  155.   /* A 16 bit relocation without overflow.  */
  156.   HOWTO (R_PPC_ADDR16_LO,       /* type */                                 
  157.      0,                    /* rightshift */                           
  158.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  159.      16,                    /* bitsize */                   
  160.      false,                    /* pc_relative */                          
  161.      0,                    /* bitpos */                               
  162.      complain_overflow_dont,/* complain_on_overflow */
  163.      bfd_elf_generic_reloc, /* special_function */                     
  164.      "R_PPC_ADDR16_LO",    /* name */
  165.      false,                    /* partial_inplace */                      
  166.      0,                /* src_mask */                             
  167.      0xffff,               /* dst_mask */                             
  168.      false),                /* pcrel_offset */
  169.  
  170.   /* The high order 16 bits of an address.  */
  171.   HOWTO (R_PPC_ADDR16_HI,       /* type */                                 
  172.      16,                    /* rightshift */                           
  173.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  174.      16,                    /* bitsize */                   
  175.      false,                    /* pc_relative */                          
  176.      0,                    /* bitpos */                               
  177.      complain_overflow_dont, /* complain_on_overflow */
  178.      bfd_elf_generic_reloc, /* special_function */                     
  179.      "R_PPC_ADDR16_HI",    /* name */
  180.      false,                    /* partial_inplace */                      
  181.      0,                /* src_mask */                             
  182.      0xffff,               /* dst_mask */                             
  183.      false),                /* pcrel_offset */
  184.  
  185.   /* The high order 16 bits of an address, plus 1 if the contents of
  186.      the low 16 bits, treated as a signed number, is negative.  */
  187.   HOWTO (R_PPC_ADDR16_HA,       /* type */                                 
  188.      16,                    /* rightshift */                           
  189.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  190.      16,                    /* bitsize */                   
  191.      false,                    /* pc_relative */                          
  192.      0,                    /* bitpos */                               
  193.      complain_overflow_dont, /* complain_on_overflow */
  194.      ppc_elf_addr16_ha_reloc, /* special_function */                     
  195.      "R_PPC_ADDR16_HA",    /* name */
  196.      false,                    /* partial_inplace */                      
  197.      0,                /* src_mask */                             
  198.      0xffff,            /* dst_mask */                             
  199.      false),                /* pcrel_offset */
  200.  
  201.   /* An absolute 16 bit branch; the lower two bits must be zero.
  202.      FIXME: we don't check that, we just clear them.  */
  203.   HOWTO (R_PPC_ADDR14,          /* type */                                 
  204.      0,                    /* rightshift */                           
  205.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  206.      16,                    /* bitsize */                   
  207.      false,                    /* pc_relative */                          
  208.      0,                    /* bitpos */                               
  209.      complain_overflow_bitfield, /* complain_on_overflow */
  210.      bfd_elf_generic_reloc, /* special_function */                     
  211.      "R_PPC_ADDR14",    /* name */
  212.      false,                    /* partial_inplace */                      
  213.      0,                /* src_mask */                             
  214.      0xfffc,            /* dst_mask */                             
  215.      false),                /* pcrel_offset */
  216.  
  217.   /* An absolute 16 bit branch, for which bit 10 should be set to
  218.      indicate that the branch is expected to be taken.  The lower two
  219.      bits must be zero.  */
  220.   HOWTO (R_PPC_ADDR14_BRTAKEN,  /* type */                                 
  221.      0,                    /* rightshift */                           
  222.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  223.      16,                    /* bitsize */                   
  224.      false,                    /* pc_relative */                          
  225.      0,                    /* bitpos */                               
  226.      complain_overflow_bitfield, /* complain_on_overflow */
  227.      ppc_elf_unsupported_reloc, /* special_function */             
  228.      "R_PPC_ADDR14_BRTAKEN",/* name */
  229.      false,                    /* partial_inplace */                      
  230.      0,                /* src_mask */                             
  231.      0xfffc,              /* dst_mask */                             
  232.      false),                /* pcrel_offset */
  233.  
  234.   /* An absolute 16 bit branch, for which bit 10 should be set to
  235.      indicate that the branch is not expected to be taken.  The lower
  236.      two bits must be zero.  */
  237.   HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */                                 
  238.      0,                    /* rightshift */                           
  239.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  240.      16,                    /* bitsize */                   
  241.      false,                    /* pc_relative */                          
  242.      0,                    /* bitpos */                               
  243.      complain_overflow_bitfield, /* complain_on_overflow */
  244.      ppc_elf_unsupported_reloc, /* special_function */             
  245.      "R_PPC_ADDR14_BRNTAKEN",/* name */
  246.      false,                    /* partial_inplace */                      
  247.      0,                /* src_mask */                             
  248.      0xfffc,            /* dst_mask */                             
  249.      false),                /* pcrel_offset */
  250.  
  251.   /* A relative 26 bit branch; the lower two bits must be zero.  */
  252.   HOWTO (R_PPC_REL24,           /* type */                                 
  253.      0,                    /* rightshift */                           
  254.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  255.      26,                    /* bitsize */                   
  256.      true,                    /* pc_relative */                          
  257.      0,                    /* bitpos */                               
  258.      complain_overflow_signed, /* complain_on_overflow */
  259.      bfd_elf_generic_reloc,    /* special_function */                     
  260.      "R_PPC_REL24",        /* name */
  261.      false,                    /* partial_inplace */                      
  262.      0,                /* src_mask */                             
  263.      0x3fffffc,            /* dst_mask */                             
  264.      true),                 /* pcrel_offset */
  265.  
  266.   /* A relative 16 bit branch; the lower two bits must be zero.  */
  267.   HOWTO (R_PPC_REL14,           /* type */                                 
  268.      0,                    /* rightshift */                           
  269.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  270.      16,                    /* bitsize */                   
  271.      true,                    /* pc_relative */                          
  272.      0,                    /* bitpos */                               
  273.      complain_overflow_signed, /* complain_on_overflow */
  274.      bfd_elf_generic_reloc, /* special_function */                     
  275.      "R_PPC_REL14",        /* name */
  276.      false,                    /* partial_inplace */                      
  277.      0,                /* src_mask */                             
  278.      0xfffc,            /* dst_mask */                             
  279.      true),                 /* pcrel_offset */
  280.  
  281.   /* A relative 16 bit branch.  Bit 10 should be set to indicate that
  282.      the branch is expected to be taken.  The lower two bits must be
  283.      zero.  */
  284.   HOWTO (R_PPC_REL14_BRTAKEN,   /* type */                                 
  285.      0,                    /* rightshift */                           
  286.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  287.      16,                    /* bitsize */                   
  288.      false,                    /* pc_relative */                          
  289.      0,                    /* bitpos */                               
  290.      complain_overflow_signed, /* complain_on_overflow */
  291.      ppc_elf_unsupported_reloc, /* special_function */             
  292.      "R_PPC_REL14_BRTAKEN",    /* name */
  293.      false,                    /* partial_inplace */                      
  294.      0,                /* src_mask */                             
  295.      0xfffc,            /* dst_mask */                             
  296.      true),                 /* pcrel_offset */
  297.  
  298.   /* A relative 16 bit branch.  Bit 10 should be set to indicate that
  299.      the branch is not expected to be taken.  The lower two bits must
  300.      be zero.  */
  301.   HOWTO (R_PPC_REL14_BRNTAKEN,  /* type */                                 
  302.      0,                    /* rightshift */                           
  303.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  304.      16,                    /* bitsize */                   
  305.      false,                    /* pc_relative */                          
  306.      0,                    /* bitpos */                               
  307.      complain_overflow_signed, /* complain_on_overflow */
  308.      ppc_elf_unsupported_reloc, /* special_function */             
  309.      "R_PPC_REL14_BRNTAKEN",/* name */
  310.      false,                    /* partial_inplace */                      
  311.      0,                /* src_mask */                             
  312.      0xfffc,            /* dst_mask */                             
  313.      true),                 /* pcrel_offset */
  314.  
  315.   /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
  316.      symbol.  */
  317.   HOWTO (R_PPC_GOT16,           /* type */                                 
  318.      0,                    /* rightshift */                           
  319.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  320.      16,                    /* bitsize */                   
  321.      false,                    /* pc_relative */                          
  322.      0,                    /* bitpos */                               
  323.      complain_overflow_bitfield, /* complain_on_overflow */
  324.      ppc_elf_got16_reloc,    /* special_function */                     
  325.      "R_PPC_GOT16",        /* name */
  326.      false,                    /* partial_inplace */                      
  327.      0,                /* src_mask */                             
  328.      0xffff,            /* dst_mask */                             
  329.      false),                /* pcrel_offset */
  330.  
  331.   /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
  332.      the symbol.  */
  333.   HOWTO (R_PPC_GOT16_LO,        /* type */                                 
  334.      0,                    /* rightshift */                           
  335.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  336.      16,                    /* bitsize */                   
  337.      false,                    /* pc_relative */                          
  338.      0,                    /* bitpos */                               
  339.      complain_overflow_bitfield, /* complain_on_overflow */
  340.      ppc_elf_got16_reloc,    /* special_function */                     
  341.      "R_PPC_GOT16_LO",    /* name */
  342.      false,                    /* partial_inplace */                      
  343.      0,                /* src_mask */                             
  344.      0xffff,            /* dst_mask */                             
  345.      false),                /* pcrel_offset */
  346.  
  347.   /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
  348.      the symbol.  */
  349.   HOWTO (R_PPC_GOT16_HI,        /* type */                                 
  350.      16,                    /* rightshift */                           
  351.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  352.      16,                    /* bitsize */                   
  353.      false,                    /* pc_relative */                          
  354.      0,                    /* bitpos */                               
  355.      complain_overflow_bitfield, /* complain_on_overflow */
  356.      ppc_elf_got16_reloc,    /* special_function */                     
  357.      "R_PPC_GOT16_HI",    /* name */
  358.      false,                    /* partial_inplace */                      
  359.      0,                /* src_mask */                             
  360.      0xffff,            /* dst_mask */                             
  361.      false),                 /* pcrel_offset */
  362.  
  363.   /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
  364.      the symbol.  FIXME: Not supported.  */
  365.   HOWTO (R_PPC_GOT16_HA,        /* type */                                 
  366.      0,                    /* rightshift */                           
  367.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  368.      16,                    /* bitsize */                   
  369.      false,                    /* pc_relative */                          
  370.      0,                    /* bitpos */                               
  371.      complain_overflow_bitfield, /* complain_on_overflow */
  372.      ppc_elf_unsupported_reloc, /* special_function */                     
  373.      "R_PPC_GOT16_HA",    /* name */
  374.      false,                    /* partial_inplace */                      
  375.      0,                /* src_mask */                             
  376.      0xffff,            /* dst_mask */                             
  377.      false),                /* pcrel_offset */
  378.  
  379.   /* Like R_PPC_REL24, but referring to the procedure linkage table
  380.      entry for the symbol.  FIXME: Not supported.  */
  381.   HOWTO (R_PPC_PLT24,           /* type */                                 
  382.      0,                    /* rightshift */                           
  383.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  384.      26,                    /* bitsize */                   
  385.      true,                    /* pc_relative */                          
  386.      0,                    /* bitpos */                               
  387.      complain_overflow_signed, /* complain_on_overflow */
  388.      bfd_elf_generic_reloc, /* special_function */                     
  389.      "R_PPC_PLT24",        /* name */
  390.      false,                    /* partial_inplace */                      
  391.      0,                /* src_mask */                             
  392.      0x3fffffc,            /* dst_mask */                             
  393.      true),                 /* pcrel_offset */
  394.  
  395.   /* This is used only by the dynamic linker.  The symbol should exist
  396.      both in the object being run and in some shared library.  The
  397.      dynamic linker copies the data addressed by the symbol from the
  398.      shared library into the object.  I have no idea what the purpose
  399.      of this is.  */
  400.   HOWTO (R_PPC_COPY,            /* type */                                 
  401.      0,                    /* rightshift */                           
  402.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  403.      32,                    /* bitsize */                   
  404.      false,                    /* pc_relative */                          
  405.      0,                    /* bitpos */                               
  406.      complain_overflow_bitfield, /* complain_on_overflow */
  407.      bfd_elf_generic_reloc, /* special_function */                     
  408.      "R_PPC_COPY",        /* name */
  409.      false,                    /* partial_inplace */                      
  410.      0,                /* src_mask */                             
  411.      0,                    /* dst_mask */                             
  412.      false),                /* pcrel_offset */
  413.  
  414.   /* Like R_PPC_ADDR32, but used when setting global offset table
  415.      entries.  */
  416.   HOWTO (R_PPC_GLOB_DAT,        /* type */                                 
  417.      0,                    /* rightshift */                           
  418.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  419.      32,                    /* bitsize */                   
  420.      false,                    /* pc_relative */                          
  421.      0,                    /* bitpos */                               
  422.      complain_overflow_bitfield, /* complain_on_overflow */
  423.      bfd_elf_generic_reloc, /* special_function */                     
  424.      "R_PPC_GLOB_DAT",    /* name */
  425.      false,                    /* partial_inplace */                      
  426.      0,                /* src_mask */                             
  427.      0xffffffff,          /* dst_mask */                             
  428.      false),                /* pcrel_offset */
  429.  
  430.   /* Marks a procedure linkage table entry for a symbol.  */
  431.   HOWTO (R_PPC_JMP_SLOT,        /* type */                                 
  432.      0,                    /* rightshift */                           
  433.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  434.      32,                    /* bitsize */                   
  435.      false,                    /* pc_relative */                          
  436.      0,                    /* bitpos */                               
  437.      complain_overflow_bitfield, /* complain_on_overflow */
  438.      bfd_elf_generic_reloc, /* special_function */                     
  439.      "R_PPC_JMP_SLOT",    /* name */
  440.      false,                    /* partial_inplace */                      
  441.      0,                /* src_mask */                             
  442.      0,                    /* dst_mask */                             
  443.      false),                /* pcrel_offset */
  444.  
  445.   /* Used only by the dynamic linker.  When the object is run, this
  446.      longword is set to the load address of the object, plus the
  447.      addend.  */
  448.   HOWTO (R_PPC_RELATIVE,        /* type */                                 
  449.      0,                    /* rightshift */                           
  450.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  451.      32,                    /* bitsize */                   
  452.      false,                    /* pc_relative */                          
  453.      0,                    /* bitpos */                               
  454.      complain_overflow_bitfield, /* complain_on_overflow */
  455.      bfd_elf_generic_reloc, /* special_function */                     
  456.      "R_PPC_RELATIVE",    /* name */
  457.      false,                    /* partial_inplace */                      
  458.      0,                /* src_mask */                             
  459.      0xffffffff,           /* dst_mask */                             
  460.      false),                /* pcrel_offset */
  461.  
  462.   /* Like R_PPC_REL24, but uses the value of the symbol within the
  463.      object rather than the final value.  Normally used for
  464.      _GLOBAL_OFFSET_TABLE_.  FIXME: Not supported.  */
  465.   HOWTO (R_PPC_LOCAL24PC,       /* type */                                 
  466.      0,                    /* rightshift */                           
  467.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  468.      26,                    /* bitsize */                   
  469.      true,                    /* pc_relative */                          
  470.      0,                    /* bitpos */                               
  471.      complain_overflow_signed, /* complain_on_overflow */
  472.      ppc_elf_unsupported_reloc, /* special_function */                     
  473.      "R_PPC_LOCAL24PC",    /* name */
  474.      false,                    /* partial_inplace */                      
  475.      0,                /* src_mask */                             
  476.      0x3fffffc,           /* dst_mask */                             
  477.      true),                 /* pcrel_offset */
  478.  
  479.   /* Like R_PPC_ADDR32, but may be unaligned.  */
  480.   HOWTO (R_PPC_UADDR32,         /* type */                                 
  481.      0,                    /* rightshift */                           
  482.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  483.      32,                    /* bitsize */                   
  484.      false,                    /* pc_relative */                          
  485.      0,                    /* bitpos */                               
  486.      complain_overflow_bitfield, /* complain_on_overflow */
  487.      bfd_elf_generic_reloc, /* special_function */                     
  488.      "R_PPC_UADDR32",    /* name */
  489.      false,                    /* partial_inplace */                      
  490.      0,                /* src_mask */                             
  491.      0xffffffff,           /* dst_mask */                             
  492.      false),                /* pcrel_offset */
  493.  
  494.   /* Like R_PPC_ADDR16, but may be unaligned.  */
  495.   HOWTO (R_PPC_UADDR16,         /* type */                                 
  496.      0,                    /* rightshift */                           
  497.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  498.      16,                    /* bitsize */                   
  499.      false,                    /* pc_relative */                          
  500.      0,                    /* bitpos */                               
  501.      complain_overflow_bitfield, /* complain_on_overflow */
  502.      bfd_elf_generic_reloc, /* special_function */                     
  503.      "R_PPC_UADDR16",    /* name */
  504.      false,                    /* partial_inplace */                      
  505.      0,                /* src_mask */                             
  506.      0xffff,               /* dst_mask */                             
  507.      false),                /* pcrel_offset */
  508.  
  509.   /* The remaining relocs are from the Embedded ELF ABI, and are not
  510.      in the SVR4 ELF ABI.  */
  511.  
  512.   /* Like R_PPC_GOT16, but using the constant GOT table.  */
  513.   HOWTO (R_PPC_CGOT16,          /* type */                                 
  514.      0,                    /* rightshift */                           
  515.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  516.      16,                    /* bitsize */                   
  517.      false,                    /* pc_relative */                          
  518.      0,                    /* bitpos */                               
  519.      complain_overflow_bitfield, /* complain_on_overflow */
  520.      ppc_elf_got16_reloc,    /* special_function */                     
  521.      "R_PPC_CGOT16",    /* name */
  522.      false,                    /* partial_inplace */                      
  523.      0,                /* src_mask */                             
  524.      0xffff,           /* dst_mask */                             
  525.      false),                /* pcrel_offset */
  526.  
  527.   /* Like R_PPC_GOT16_LO, but using the constant GOT table.  */
  528.   HOWTO (R_PPC_CGOT16_LO,       /* type */                                 
  529.      0,                    /* rightshift */                           
  530.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  531.      16,                    /* bitsize */                   
  532.      false,                    /* pc_relative */                          
  533.      0,                    /* bitpos */                               
  534.      complain_overflow_bitfield, /* complain_on_overflow */
  535.      ppc_elf_got16_reloc,    /* special_function */                     
  536.      "R_PPC_CGOT16_LO",    /* name */
  537.      false,                    /* partial_inplace */                      
  538.      0,                /* src_mask */                             
  539.      0xffff,           /* dst_mask */                             
  540.      false),                /* pcrel_offset */
  541.  
  542.   /* Like R_PPC_GOT16_HI, but using the constant GOT table.  */
  543.   HOWTO (R_PPC_CGOT16_HI,       /* type */                                 
  544.      16,                    /* rightshift */                           
  545.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  546.      16,                    /* bitsize */                   
  547.      false,                    /* pc_relative */                          
  548.      0,                    /* bitpos */                               
  549.      complain_overflow_bitfield, /* complain_on_overflow */
  550.      ppc_elf_got16_reloc,    /* special_function */                     
  551.      "R_PPC_CGOT16_HI",    /* name */
  552.      false,                    /* partial_inplace */                      
  553.      0,                /* src_mask */                             
  554.      0xffff,           /* dst_mask */                             
  555.      false),                /* pcrel_offset */
  556.  
  557.   /* Like R_PPC_GOT16_HA, but using the constant GOT table.  */
  558.   HOWTO (R_PPC_CGOT16_HA,       /* type */                                 
  559.      0,                    /* rightshift */                           
  560.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  561.      16,                    /* bitsize */                   
  562.      false,                    /* pc_relative */                          
  563.      0,                    /* bitpos */                               
  564.      complain_overflow_bitfield, /* complain_on_overflow */
  565.      ppc_elf_unsupported_reloc, /* special_function */                     
  566.      "R_PPC_CGOT16_HA",    /* name */
  567.      false,                    /* partial_inplace */                      
  568.      0,                /* src_mask */                             
  569.      0xffff,           /* dst_mask */                             
  570.      false),                /* pcrel_offset */
  571.  
  572.   /* The dedicated GOT register.  */
  573.   HOWTO (R_PPC_GOT_REG,         /* type */                                 
  574.      0,                    /* rightshift */                           
  575.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  576.      5,                    /* bitsize */                   
  577.      false,                    /* pc_relative */                          
  578.      0,                    /* bitpos */                               
  579.      complain_overflow_bitfield, /* complain_on_overflow */
  580.      ppc_elf_unsupported_reloc, /* special_function */                     
  581.      "R_PPC_GOT_REG",    /* name */
  582.      false,                    /* partial_inplace */                      
  583.      0,                /* src_mask */                             
  584.      0x1f,           /* dst_mask */                             
  585.      false),                /* pcrel_offset */
  586.  
  587.   /* The dedicated CGOT register.  */
  588.   HOWTO (R_PPC_CGOT_REG,        /* type */                                 
  589.      0,                    /* rightshift */                           
  590.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  591.      5,                    /* bitsize */                   
  592.      false,                    /* pc_relative */                          
  593.      0,                    /* bitpos */                               
  594.      complain_overflow_bitfield, /* complain_on_overflow */
  595.      ppc_elf_unsupported_reloc, /* special_function */                     
  596.      "R_PPC_CGOT_REG",    /* name */
  597.      false,                    /* partial_inplace */                      
  598.      0,                /* src_mask */                             
  599.      0x1f,           /* dst_mask */                             
  600.      false),                /* pcrel_offset */
  601.  
  602.   /* Like R_PPC_ADDR16, but subtract the symbol.  */
  603.   HOWTO (R_PPC_NADDR16,         /* type */                                 
  604.      0,                    /* rightshift */                           
  605.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  606.      16,                    /* bitsize */                   
  607.      false,                    /* pc_relative */                          
  608.      0,                    /* bitpos */                               
  609.      complain_overflow_bitfield, /* complain_on_overflow */
  610.      ppc_elf_unsupported_reloc, /* special_function */                     
  611.      "R_PPC_NADDR16",    /* name */
  612.      false,                    /* partial_inplace */                      
  613.      0,                /* src_mask */                             
  614.      0xffff,           /* dst_mask */                             
  615.      false),                /* pcrel_offset */
  616.  
  617.   /* Like R_PPC_ADDR32, but subtract the symbol.  */
  618.   HOWTO (R_PPC_NADDR32,         /* type */                                 
  619.      0,                    /* rightshift */                           
  620.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  621.      32,                    /* bitsize */                   
  622.      false,                    /* pc_relative */                          
  623.      0,                    /* bitpos */                               
  624.      complain_overflow_bitfield, /* complain_on_overflow */
  625.      ppc_elf_unsupported_reloc, /* special_function */                     
  626.      "R_PPC_NADDR32",    /* name */
  627.      false,                    /* partial_inplace */                      
  628.      0,                /* src_mask */                             
  629.      0xffffffff,           /* dst_mask */                             
  630.      false),                /* pcrel_offset */
  631.  
  632.   /* Like R_PPC_ADDR24, but subtract the symbol.  */
  633.   HOWTO (R_PPC_NADDR24,         /* type */                                 
  634.      0,                    /* rightshift */                           
  635.      2,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  636.      26,                    /* bitsize */                   
  637.      false,                    /* pc_relative */                          
  638.      0,                    /* bitpos */                               
  639.      complain_overflow_bitfield, /* complain_on_overflow */
  640.      ppc_elf_unsupported_reloc, /* special_function */                     
  641.      "R_PPC_NADDR24",    /* name */
  642.      false,                    /* partial_inplace */                      
  643.      0,                /* src_mask */                             
  644.      0x3fffffc,           /* dst_mask */                             
  645.      false),                /* pcrel_offset */
  646.  
  647.   /* Offset of symbol relative to containing csect.  */
  648.   HOWTO (R_PPC_DISP16,          /* type */                                 
  649.      0,                    /* rightshift */                           
  650.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  651.      16,                    /* bitsize */                   
  652.      false,                    /* pc_relative */                          
  653.      0,                    /* bitpos */                               
  654.      complain_overflow_bitfield, /* complain_on_overflow */
  655.      ppc_elf_unsupported_reloc, /* special_function */                     
  656.      "R_PPC_DISP16",    /* name */
  657.      false,                    /* partial_inplace */                      
  658.      0,                /* src_mask */                             
  659.      0xffff,           /* dst_mask */                             
  660.      false),                /* pcrel_offset */
  661.  
  662.   /* Like R_PPC_GOT16, but may be converted to an address computation
  663.      instead of a load.  */
  664.   HOWTO (R_PPC_GOTRL16,         /* type */                                 
  665.      0,                    /* rightshift */                           
  666.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  667.      16,                    /* bitsize */                   
  668.      false,                    /* pc_relative */                          
  669.      0,                    /* bitpos */                               
  670.      complain_overflow_bitfield, /* complain_on_overflow */
  671.      ppc_elf_got16_reloc,    /* special_function */                     
  672.      "R_PPC_GOTRL16",    /* name */
  673.      false,                    /* partial_inplace */                      
  674.      0,                /* src_mask */                             
  675.      0xffff,           /* dst_mask */                             
  676.      false),                /* pcrel_offset */
  677.  
  678.   /* Like R_PPC_GOT16, but may be converted to a load instead of an
  679.      address computation.  */
  680.   HOWTO (R_PPC_GOTRLA16,        /* type */                                 
  681.      0,                    /* rightshift */                           
  682.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  683.      16,                    /* bitsize */                   
  684.      false,                    /* pc_relative */                          
  685.      0,                    /* bitpos */                               
  686.      complain_overflow_bitfield, /* complain_on_overflow */
  687.      ppc_elf_got16_reloc,    /* special_function */                     
  688.      "R_PPC_GOTRLA16",    /* name */
  689.      false,                    /* partial_inplace */                      
  690.      0,                /* src_mask */                             
  691.      0xffff,          /* dst_mask */                             
  692.      false),                /* pcrel_offset */
  693.  
  694.   /* Like R_PPC_CGOT16, but may be converted to an address computation
  695.      instead of a load.  */
  696.   HOWTO (R_PPC_CGOTRL16,        /* type */                                 
  697.      0,                    /* rightshift */                           
  698.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  699.      16,                    /* bitsize */                   
  700.      false,                    /* pc_relative */                          
  701.      0,                    /* bitpos */                               
  702.      complain_overflow_bitfield, /* complain_on_overflow */
  703.      ppc_elf_unsupported_reloc, /* special_function */                     
  704.      "R_PPC_CGOTRL16",    /* name */
  705.      false,                    /* partial_inplace */                      
  706.      0,                /* src_mask */                             
  707.      0xffff,           /* dst_mask */                             
  708.      false),                /* pcrel_offset */
  709.  
  710.   /* Like R_PPC_CGOT16, but may be converted to a load instead of an
  711.      address computation.  */
  712.   HOWTO (R_PPC_CGOTRLA16,       /* type */                                 
  713.      0,                    /* rightshift */                           
  714.      1,                    /* size (0 = byte, 1 = short, 2 = long) */ 
  715.      16,                    /* bitsize */                   
  716.      false,                    /* pc_relative */                          
  717.      0,                    /* bitpos */                               
  718.      complain_overflow_bitfield, /* complain_on_overflow */
  719.      ppc_elf_unsupported_reloc, /* special_function */
  720.      "R_PPC_CGOTRLA16",    /* name */
  721.      false,                    /* partial_inplace */                      
  722.      0,                /* src_mask */                             
  723.      0xffff,           /* dst_mask */                             
  724.      false),                /* pcrel_offset */
  725. };
  726.  
  727. /* Don't pretend we can deal with unsupported relocs.  */
  728.  
  729. /*ARGSUSED*/
  730. static bfd_reloc_status_type
  731. ppc_elf_unsupported_reloc (abfd, reloc_entry, symbol, data, input_section,
  732.                output_bfd, error_message)
  733.      bfd *abfd;
  734.      arelent *reloc_entry;
  735.      asymbol *symbol;
  736.      PTR data;
  737.      asection *input_section;
  738.      bfd *output_bfd;
  739.      char **error_message;
  740. {
  741.   abort ();
  742. }
  743.  
  744. /* Handle the ADDR16_HA reloc by adjusting the reloc addend.  */
  745.  
  746. static bfd_reloc_status_type
  747. ppc_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section,
  748.                  output_bfd, error_message)
  749.      bfd *abfd;
  750.      arelent *reloc_entry;
  751.      asymbol *symbol;
  752.      PTR data;
  753.      asection *input_section;
  754.      bfd *output_bfd;
  755.      char **error_message;
  756. {
  757.   bfd_vma relocation;
  758.  
  759.   if (output_bfd != (bfd *) NULL)
  760.     return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
  761.                   input_section, output_bfd, error_message);
  762.  
  763.   if (bfd_is_com_section (symbol->section))
  764.     relocation = 0;
  765.   else
  766.     relocation = symbol->value;
  767.  
  768.   relocation += (symbol->section->output_section->vma
  769.          + symbol->section->output_offset
  770.          + reloc_entry->addend);
  771.  
  772.   if ((relocation & 0x8000) != 0)
  773.     reloc_entry->addend += 0x10000;
  774.  
  775.   return bfd_reloc_continue;
  776. }
  777.  
  778. /* Handle the GOT16 reloc.  We want to use the offset within the .got
  779.    section, not the actual VMA.  This is appropriate when generating
  780.    an embedded ELF object, for which the .got section acts like the
  781.    AIX .toc section.  When and if we support PIC code, we will have to
  782.    change this, perhaps by switching off on the e_type field.  */
  783.  
  784. static bfd_reloc_status_type
  785. ppc_elf_got16_reloc (abfd, reloc_entry, symbol, data, input_section,
  786.              output_bfd, error_message)
  787.      bfd *abfd;
  788.      arelent *reloc_entry;
  789.      asymbol *symbol;
  790.      PTR data;
  791.      asection *input_section;
  792.      bfd *output_bfd;
  793.      char **error_message;
  794. {
  795.   asection *sec;
  796.  
  797.   if (output_bfd != (bfd *) NULL)
  798.     return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
  799.                   input_section, output_bfd, error_message);
  800.  
  801.   sec = bfd_get_section (*reloc_entry->sym_ptr_ptr);
  802.   BFD_ASSERT (bfd_is_und_section (sec)
  803.           || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
  804.           || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0);
  805.   reloc_entry->addend -= sec->output_section->vma;
  806.   return bfd_reloc_continue;
  807. }
  808.  
  809. /* Map BFD reloc types to PowerPC ELF reloc types.  */
  810.  
  811. struct powerpc_reloc_map
  812. {
  813.   unsigned char bfd_reloc_val;
  814.   unsigned char elf_reloc_val;
  815. };
  816.  
  817. static const struct powerpc_reloc_map powerpc_reloc_map[] =
  818. {
  819.   { BFD_RELOC_NONE, R_PPC_NONE, },
  820.   { BFD_RELOC_32, R_PPC_ADDR32 },
  821.   { BFD_RELOC_CTOR, R_PPC_ADDR32 },
  822.   { BFD_RELOC_PPC_B26, R_PPC_REL24 },
  823.   { BFD_RELOC_PPC_BA26, R_PPC_ADDR24 },
  824.   { BFD_RELOC_PPC_TOC16, R_PPC_GOT16 }
  825. };
  826.  
  827. static const struct reloc_howto_struct *
  828. bfd_elf32_bfd_reloc_type_lookup (abfd, code)
  829.      bfd *abfd;
  830.      bfd_reloc_code_real_type code;
  831. {
  832.   int i;
  833.  
  834.   for (i = 0;
  835.        i < sizeof (powerpc_reloc_map) / sizeof (struct powerpc_reloc_map);
  836.        i++)
  837.     {
  838.       if (powerpc_reloc_map[i].bfd_reloc_val == code)
  839.     return &elf_powerpc_howto_table[powerpc_reloc_map[i].elf_reloc_val];
  840.     }
  841.  
  842.   return NULL;
  843. }
  844.  
  845. /* Set the howto pointer for a PowerPC ELF reloc.  */
  846.  
  847. static void
  848. powerpc_info_to_howto (abfd, cache_ptr, dst)
  849.      bfd *abfd;
  850.      arelent *cache_ptr;
  851.      Elf32_Internal_Rela *dst;
  852. {
  853.   BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
  854.   cache_ptr->howto = &elf_powerpc_howto_table[ELF32_R_TYPE (dst->r_info)];
  855. }
  856.  
  857. #define TARGET_BIG_SYM        bfd_elf32_powerpc_vec
  858. #define TARGET_BIG_NAME        "elf32-powerpc"
  859. #define ELF_ARCH        bfd_arch_powerpc
  860. #define ELF_MACHINE_CODE    EM_CYGNUS_POWERPC
  861. #define ELF_MAXPAGESIZE        0x10000
  862. #define elf_info_to_howto    powerpc_info_to_howto
  863.  
  864. #include "elf32-target.h"
  865.